import os
import random
import pygame

class Tank:
    def __init__(self):
        self._tank = pygame.image.load(f"{os.path.dirname(__file__)}/images/tank_green.png").convert_alpha()
        self._tank = pygame.transform.rotate(self._tank, 180) # 旋转180度
        self._x = 0
        self._y = 0
        self._speedY = random.randint(3, 10)/10
        self._speedX = random.randint(1, 20)/10 - 1.0

        self.width = self._tank.get_width()
        self.length = self._tank.get_height()
    
    def SetPositon(self, x, y):
        self._x = x
        self._y = y

    def render(self, screen):
        screen.blit(self._tank, (self._x, self._y))
    
    def update(self):
        self._y += self._speedY
        self._x += self._speedX
        if self._x < 0:
            self._speedX *= -1
        elif self._x > 800-self.width:
            self._speedX *= -1
